#define _CRT_SECURE_NO_WARNINGS
#include"test.h"
void SLprintf(SL* p)
{
	SL* arr = p;
	while (arr)
	{
		printf("%d->", arr->x);
		arr = arr->next;
	}
	printf("NULL\n");
}
SL* chuang(leixing x)
{
	SL* arr = (SL*)malloc(sizeof(SL));
	if (arr == NULL)
	{
		perror("malloc arr");
		return;
	}
	arr->next = NULL;
	arr->x = x;
	return arr;
}
void SLwcha(SL** p, leixing x)
{
	if (*p == NULL)
	{
		*p = chuang(x);
	}
	else
	{
		SL* arr = *p;
		while (arr->next)
		{
			arr = arr->next;
		}
		arr->next = chuang(x);
	}
}
void SLtcha(SL** p, leixing x)
{
	if (*p == NULL)
	{
		*p = chuang(x);
	}
	else
	{
		SL* arr = chuang(x);
		arr->next = *p;
		*p = arr;
	}
}
void SLwshan(SL** p)
{
	assert(p&&*p);
	if ((*p)->next == NULL)
	{
		free(*p);
		*p = NULL;
	}
	else
	{
		SL* arr1 = *p;
		SL* arr2 = *p;
		while (arr2->next)
		{
			arr1 = arr2;
			arr2 = arr2->next;
		}
		free(arr2);
		arr1->next = NULL;
		arr2 = NULL;
	}
}
void SLtshan(SL** p)
{
	assert(p && *p);
	SL* arr = (*p)->next;
	free(*p);
	*p = arr;
}
SL* SLczao(SL* p, leixing x)
{
	assert(p);
	SL* arr = p;
	while (arr)
	{
		if (arr->x == x)
		{
			return arr;
		}
		arr = arr->next;
	}
	return NULL;
}
void SLzqcha(SL** p, SL* wei, leixing x)
{
	assert(p&&*p);
	assert(wei);
	if (*p == wei)
	{
		SLtcha(p, x);
	}
	else
	{
		SL* arr = *p;
		while (arr->next != wei)
		{
			arr = arr->next;
		}
			SL* arr2 = chuang(x);
			arr2->next = wei;
			arr->next = arr2;
	}	
}
void SLzqshan(SL** p, SL* wei)
{
	assert(p&&*p);
	if (*p == wei)
	{
		SLtshan(p);
	}
	else
	{
		SL* arr = *p;
		while (arr->next != wei)
		{
			arr = arr->next;
		}		
			arr->next = wei->next;
			free(wei);
			wei = NULL;
	}
}
void SLzhcha(SL* wei, leixing x)
{
	assert(wei);
	SL* arr = chuang(x);
	arr->next = wei->next;
	wei->next = arr;
}
void SLzhshan(SL* wei)
{
	assert(wei&&wei->next);
	SL* arr = wei->next;
	wei->next = arr->next;
	free(arr);
	arr = NULL;
}
void SLget(SL** p)
{
	assert(p&&*p);
	SL* arr = *p;
	while (arr)
	{
		SL* ass = arr->next;
		free(arr);
		arr = ass;
	}
	*p = arr;
}